package com.qianbao.qianbaobusiness.ui.cashier.switchshop;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.TextView;

import com.androidbase.widget.recycleadpter.BaseRecycleViewAdapter;
import com.qianbao.qianbaobusiness.R;
import com.qianbao.qianbaobusiness.json.MerchantInfo;

/**
 * @author: Routee
 * @date 2018/6/14
 * @mail wangc4@qianbaocard.com
 * ------------1.本类由Routee开发,阅读、修改时请勿随意修改代码排版格式后提交到git。
 * ------------2.阅读本类时，发现不合理请及时指正.
 * ------------3.如需在本类内部进行修改,请先联系Routee,若未经同意修改此类后造成损失本人概不负责。
 */
public class SwitchShopAdapter extends BaseRecycleViewAdapter<MerchantInfo> {
    private PickListener pickListener;


    public SwitchShopAdapter(Context context, PickListener pickListener) {
        super(context);
        this.pickListener = pickListener;
    }

    @Override
    protected void onBindBaseViewHolder(RecyclerView.ViewHolder holder, final MerchantInfo item) {
        final ShopViewHolder vh = (ShopViewHolder) holder;
        vh.tvName.setText(item.merchantName);
        vh.tvAdd.setText(item.shopProviceName + "-" + item.shopCityName + "-" + item.shopDistrictName);
        vh.cb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                item.isSelected = isChecked;
                pickListener.pickChange();
            }
        });
        vh.cb.setChecked(item.isSelected);
    }

    @Override
    protected RecyclerView.ViewHolder onCreateBaseViewHolder(ViewGroup parent, int viewType) {
        return new ShopViewHolder(LayoutInflater.from(mContext).inflate(R.layout.item_shop_select, null, false));
    }

    @Override
    protected int getBaseItemViewType(int position) {
        return 0;
    }

    class ShopViewHolder extends RecyclerView.ViewHolder {
        TextView tvName;
        TextView tvAdd;
        CheckBox cb;

        public ShopViewHolder(View itemView) {
            super(itemView);
            tvName = itemView.findViewById(R.id.tv_name);
            tvAdd = itemView.findViewById(R.id.tv_add);
            cb = itemView.findViewById(R.id.cb);
        }
    }

    public interface PickListener {
        void pickChange();
    }
}
